package com.leyou.common.advice;

import com.leyou.common.exceptions.LyException;
import com.leyou.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author 虎哥
 */
@ControllerAdvice
public class ExceptionAdvice {

    /**
     * 注解：@ExceptionHandler声明要处理的异常，每当controller中抛出这个异常，就会交给当前方法处理
     * @param e 捕获到的异常
     * @return
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e){
        e.printStackTrace();
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }

}
